//
//  MessageHistoryCell.m
//  AILock
//
//  Created by 谭亚明 on 2020/7/13.
//  Copyright © 2020 tym. All rights reserved.
//

#import "MessageHistoryCell.h"
#import "DrawCyclesView.h"
#import "Dashline.h"
#import "UnusualPoliceVC.h"
@interface MessageHistoryCell()

@property(nonatomic,weak) IBOutlet UIImageView *headImage;
@property(nonatomic,weak) IBOutlet UILabel  *nameLab;
@property(nonatomic,weak) IBOutlet UILabel *contLab;
@property(nonatomic,weak) IBOutlet UILabel *timeLab;

@end


@implementation MessageHistoryCell

-(void)awakeFromNib{
    [super awakeFromNib];
    
    
    
}

-(void)setLineType:(NSInteger)type{
    for(UIView *view in  self.contentView.subviews) {
        if ([view isKindOfClass:[Dashline class]] || [view isKindOfClass:[DrawCyclesView class]]) {
            [view removeFromSuperview];
        }
    }
    
    if (type == 0) {
        Dashline *line = [[Dashline alloc] initWithFrame:CGRectMake(19, 20, 0.5, [MessageHistoryCell cellForHeight]) withLineLength:3 withLineSpacing:3 withLineColor:rgba(147, 148, 150)];
        [self.contentView addSubview:line];
    }else if(type == 1){
        Dashline *line = [[Dashline alloc] initWithFrame:CGRectMake(19, 0, 0.5, [MessageHistoryCell cellForHeight]/2) withLineLength:3 withLineSpacing:3 withLineColor:rgba(147, 148, 150)];
        [self.contentView addSubview:line];
    }else if(type == 2){
        Dashline *line = [[Dashline alloc] initWithFrame:CGRectMake(19, 0, 0.5, [MessageHistoryCell cellForHeight]) withLineLength:3 withLineSpacing:3 withLineColor:rgba(147, 148, 150)];
        [self.contentView addSubview:line];
    }else if(type == 3){
        
        
    }
    
    DrawCyclesView*cView =[[DrawCyclesView alloc]initWithFrame:CGRectMake(13, 20, 13, 13)];
    [self.contentView addSubview:cView];
}

+(NSString*)identifier{
    return @"messageHistorycell";
}

+(CGFloat)cellForHeight{
    return 60;
}

-(void)setMessageModel:(EquipmentMessageModel *)messageModel{
    
    if (messageModel.operationSourceName) {
        self.nameLab.text = messageModel.operationName;
        self.contLab.text = messageModel.operationSourceName;
        
        if([messageModel.operationSource isEqualToString:@"00"]) {
            self.headImage.image = [UIImage imageNamed:@"icon_zhiwen"];
        }else if([messageModel.operationSource isEqualToString:@"01"]){
            self.headImage.image = [UIImage imageNamed:@"icon_ka"];
        }else if([messageModel.operationSource isEqualToString:@"02"]){
            self.headImage.image = [UIImage imageNamed:@"icon_mima"];
        }else if([messageModel.operationSource isEqualToString:@"03"]){
            self.headImage.image = [UIImage imageNamed:@"icon_mima"];
        }else if([messageModel.operationSource isEqualToString:@"05"]){
            self.headImage.image = [UIImage imageNamed:@"icon_yaokong"];
        }else if([messageModel.operationSource isEqualToString:@"09"]){
            self.headImage.image = [UIImage imageNamed:@"icon_shouji"];
        }else{
            self.headImage.image = [UIImage imageNamed:@"icon／shebei"];
        }
        
    }else if(messageModel.alarmName){ //报警
        self.nameLab.text = messageModel.alarmName;
        self.contLab.text = messageModel.alarmDesc;
        
        switch (messageModel.alarmCode) {
            case 0:
                self.headImage.image = [UIImage imageNamed:@"icon_xitong 2"];
                break;
            case 1:
                self.headImage.image = [UIImage imageNamed:@"icon_didian"];
                break;
                //            case 2:
                //                self.headImage.image = [UIImage imageNamed:@"icon_baojing"];
                //                break;
                //            case 3: //胁迫报警
                //
                //                break;
                //            case 4: //逗留报警
                //
                //                break;
                //            case 5: //高温报警
                //
                //                break;
                //            case 6:   //指纹是错
                //
                //                break;
                //            case 7: //卡片是错
                //
                //                break;
                //            case 8: //密码是错
                //
                //                break;
                //            case 9: //敲门
                //
                //                break;
                //            case 10: //SOS
                //
                //                break;
                //            case 11: //门未关好
                //
                //                break;
                //            case 12: //常开提醒
                //
                //                break;
                //            case 13: //常开提醒
                //
                //                break;
                //            case 14: //反锁开启
                //
                //                break;
                //            case 15: //反锁关闭
                //
                //                break;
            default:
                self.headImage.image = [UIImage imageNamed:@"icon_baojing"];
                break;
        }
        
    }else if(messageModel.operationDesc){
        self.nameLab.text = messageModel.title;
        self.contLab.text = messageModel.operationDesc;
        
        if(messageModel.type > 10){
            switch (messageModel.equipmentUserType) {
                case 0:
                    self.headImage.image = [UIImage imageNamed:@"icon_option_zhiwen"];
                    break;
                case 1:
                    self.headImage.image = [UIImage imageNamed:@"icon_option_ka"];
                    break;
                case 2:
                    self.headImage.image = [UIImage imageNamed:@"icon_option_mima"];
                    break;
                case 5:
                    self.headImage.image = [UIImage imageNamed:@"icon_optin_yaokong"];
                    break;
            }
        }else{
            self.headImage.image = [UIImage imageNamed:@"icon_mensuopz"];
        }
    }
    
    
    self.timeLab.text = [messageModel.createTime substringWithRange:NSMakeRange(10, 6)];
}

@end
